# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=xerces-c
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.2.4
pkgrel=1
pkgdesc="A validating XML parser written in a portable subset of C++ (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://xerces.apache.org/xerces-c"
license=('spdx:Apache-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         # "${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-icu")
options=('staticlibs' 'strip')
source=("https://archive.apache.org/dist/xerces/c/3/sources/xerces-c-${pkgver}.tar.gz"
        001-no-undefined.patch
        002-duplicate-instantiation.patch
        003-makefile-add-ws2_32.patch
        004-check-cpuid-header-for-arm64.patch)
sha256sums=('3d8ec1c7f94e38fee0e4ca5ad1e1d9db23cbf3a10bba626f6b4afa2dedafe5ab'
            'a95206b0e17942ebe5bffcafbb9c9555b1f3c922b9a8f7cdea950acab48eecd5'
            '028b0a5c021d63c74db24bfca898c9e6df7074c1597896a6bfd48d76f64b9cb8'
            '28f8dd21779453ebedaf6aba0fee0502e11e3fc22f805c6ede09162222810e69'
            '9ee9437b0fe336972bcf979d8aedff172287a802eb302768fb17e44e616783d4')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-no-undefined.patch
  patch -p1 -i ${srcdir}/002-duplicate-instantiation.patch
  patch -p1 -i ${srcdir}/003-makefile-add-ws2_32.patch
  patch -p1 -i ${srcdir}/004-check-cpuid-header-for-arm64.patch
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  "${srcdir}"/${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
